package com.gitee.zeric.codec.controller;


import com.gitee.zeric.codec.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author zj
 * @date 2021-06-08
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    /**
     * 处理自定义的业务异常
     *
     * @param e   异常
     * @return
     */
    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public R bizExceptionHandler(BizException e) {
        log.error("发生业务异常！提示信息：{}", e.getErrorMsg());
        return R.failed(e.getErrorMsg());
    }
}
